package org.pas.fb2.tag;

public abstract class AbstractTitleTag extends Tag {

    private final StringBuilder text = new StringBuilder();

    AbstractTitleTag(Tag parent) {
        super(parent);
        emptyLine(false);
    }

    @Override
    public Tag onChild(String name) {
        if (StrongTag.NAME.equals(name)) {
            return new StrongTag(this);
        } else if (ParagraphTag.NAME.equals(name)) {
            return new ParagraphTag(this);
        } else if (EmptyLineTag.NAME.equals(name)) {
            return new EmptyLineTag(this);
        }
        return super.onChild(name);
    }

    @Override
    protected void doClose() {
        out(removeSpaces(text));
        emptyLine(false);
    }

    @Override
    public void onChars(char ch[], int start, int length) {
        text.append(ch, start, length);
    }

    public CharSequence getText() {
        return text;
    }
}